package cn.gz.demo.ui;

import android.graphics.Color;
import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

import cn.gz.demo.R;
import cn.gz.demo.adapter.FragmentTabAdapter;
import cn.gz.demo.databinding.TabLayoutBinding;
import cn.gz.demo.ui.base.BaseActivity;
import cn.gz.demo.ui.tab_fragment.FoundFragment;
import cn.gz.demo.ui.tab_fragment.HomeFrament;
import cn.gz.demo.ui.tab_fragment.MeFragment;
import cn.gz.demo.ui.tab_fragment.MessageFrament;
import cn.gz.demo.ui.tab_fragment.TabFragment;
import cn.gz.demo.utils.TabUtils;

/**
 * Created by Lyz on 2017/3/8.
 */
public class TabLayoutViewPager2Activity extends BaseActivity {
    private TabLayoutBinding binding;
    private FragmentTabAdapter adapter;
    public List<Fragment> fragments = new ArrayList<Fragment>();
    private List<String> titles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_tablayout);

        initView();
    }

    private void initView() {

        titles.clear();
        titles.add("报表");
        titles.add("待处理");
        titles.add("全部");
        titles.add("全部");
        titles.add("全部");
        titles.add("全部");
        titles.add("全部");

        fragments.add(new TabFragment());
        fragments.add(new TabFragment());
        fragments.add(new HomeFrament());
        fragments.add(new FoundFragment());
        fragments.add(new MeFragment());
        fragments.add(new MessageFrament());

        binding.indicator.setBackgroundColor(Color.WHITE);
        CommonNavigator navigator = TabUtils.getInstance().initNormalTab(context, binding.tabViewpager, titles);
        binding.indicator.setNavigator(navigator);
        ViewPagerHelper.bind(binding.indicator, binding.tabViewpager);

        adapter = new FragmentTabAdapter(getSupportFragmentManager(), fragments, titles);
        binding.tabViewpager.setAdapter(adapter);
        binding.tabViewpager.setOffscreenPageLimit(fragments.size());
    }
}
